package com.byxy.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import com.byxy.entity.Tab;

public interface TabDao {
	@Select("select * from tab")
	@Results({ @Result(column = "tab_id", property = "tabId", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "tab_name", property = "tabName", jdbcType = JdbcType.VARCHAR),
			@Result(column = "tab_status", property = "tabStatus", jdbcType = JdbcType.INTEGER),
			@Result(column = "forum_id", property = "forum.forumId", jdbcType = JdbcType.INTEGER) })
	List<Tab> findAll();

	@Select("select * from tab where tab_id=#{tabId}")
	@Results({ @Result(column = "tab_id", property = "tabId", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "tab_name", property = "tabName", jdbcType = JdbcType.VARCHAR),
			@Result(column = "tab_status", property = "tabStatus", jdbcType = JdbcType.INTEGER),
			@Result(column = "forum_id", property = "forum.forumId", jdbcType = JdbcType.INTEGER) })
	Tab get(Integer tabId);

	@Delete("delete from tab where tab_id=#{tabId}")
	void delete(@Param("tabId") Integer tabId);

	@Update("update tab set tab_name=#{tabName},forum_id=#{selectedForumId} where tab_id=#{tabId}")
	void update(@Param("tabName") String tabName, @Param("selectedForumId") Integer selectedForumId,
			@Param("tabId") Integer tabId);

	@Insert("insert into tab(tab_name,forum_id) values(#{tabName},#{forumId})")
	void add(@Param("tabName") String tabName, @Param("forumId") Integer forumId);

	@Update("update tab set forum_id=#{selectedForumId} where tab_id=#{tabId}")
	void updateForumId(@Param("forumId") Integer forumId, @Param("tabId") Integer tabId);
}
